package ChessBoard;

import java.util.ArrayList;


public class Bishop extends Figure {
	public Bishop(boolean isWhite, int[] position, ChessBoard board) {

		super(isWhite, position, board);
		super.value = 3;
	}

	@Override
	protected ArrayList<int[]> calculatePos() {
		super.resetAll();
		ArrayList<int[]> newMoves = new ArrayList<int[]>();
		int tmp, tmp2;
		tmp = 1;
		tmp2 = 1;
		for (int[] pos : helper(tmp, tmp2)) {
			newMoves.add(pos);
		}
		tmp = -1;
		tmp2 = 1;
		for (int[] pos : helper(tmp, tmp2)) {
			newMoves.add(pos);
		}
		tmp = -1;
		tmp2 = -1;
		for (int[] pos : helper(tmp, tmp2)) {
			newMoves.add(pos);
		}
		tmp = 1;
		tmp2 = -1;
		for (int[] pos : helper(tmp, tmp2)) {
			newMoves.add(pos);
		}

		return newMoves;
	}

	private ArrayList<int[]> helper(int tmp, int tmp2) {
		ArrayList<int[]> newMoves = new ArrayList<int[]>();
		int x = super.position[0], y = super.position[1];
		while (x +tmp >= 1 && x+tmp <= 8 && y+tmp2 >= 1 && y+tmp2 <= 8) {
			x += tmp;
			y += tmp2;
			if (!super.correspondingBoard.fieldIsEmpty(new int[] { x, y })) {
				Figure f = super.correspondingBoard.getFigure(new int[] { x, y });
				if (super.isWhite == f.isWhite) {
					if(f.value!=100)
					super.covers.add(f);
				} else {
						if (super.correspondingBoard.moveProvokesNoCheck(x, y,this))
							super.kills.add(f);

				}
				break;
			}
//			if (super.correspondingBoard.moveProvokesNoCheck(x, y,this))
				newMoves.add(new int[] { x, y });
		}
		return newMoves;
	}

	@Override
	public void checkCheck() {
		if(this.kills.contains(super.correspondingBoard.getKing(!this.isWhite)))
			this.checks=true;
		else
			this.checks=false;
		
	}

}
